package com.ruoyi.kenuo.utils;

import org.bytedeco.javacv.FFmpegFrameGrabber;
import org.bytedeco.javacv.FFmpegFrameRecorder;

import org.bytedeco.javacv.Frame;
/**
 * @author POLO_TANG
 * @version 1.0.0
 * @ClassName IncreaseVideoQuality
 * @description: TODO
 * @date 2024年08月16日
 */
public class IncreaseVideoQuality {
    public static void main(String[] args) {
        try {
            // 创建FFmpegFrameGrabber来获取视频帧
            FFmpegFrameGrabber grabber = new FFmpegFrameGrabber("input.mp4");
            grabber.start();

            // 创建FFmpegFrameRecorder来记录/调整帧
            FFmpegFrameRecorder recorder = new FFmpegFrameRecorder("output.mp4",
                    grabber.getImageWidth(),
                    grabber.getImageHeight(),
                    grabber.getAudioChannels());
            recorder.setFormat("mp4");
            recorder.setFrameRate(grabber.getFrameRate());
            recorder.setVideoBitrate(2000);
            recorder.start();

            Frame frame;
            // 循环抓取帧并记录
            while ((frame = grabber.grabFrame()) != null) {
                recorder.record(frame);
            }

            // 停止记录和抓取
            recorder.stop();
            grabber.stop();

        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
